#include "stdafx.h"
#include "ModelListClass.h"


CModelListClass::CModelListClass(void) : m_nModelCount(0), m_pModelInfoList(nullptr)
{
}


CModelListClass::~CModelListClass(void)
{
}

bool CModelListClass::Initialize(int nNumModels)
{
	float fRed;
	float fGreen;
	float fBlue;

	m_nModelCount = nNumModels;

	m_pModelInfoList = new ModelInfoType[m_nModelCount];
	if(m_pModelInfoList == nullptr)
	{
		DEBUG_OUTPUT("Failed to create new modelinfo list pointer");
		return false;
	}

	srand((unsigned int)time(0));

	for(int i = 0; i < m_nModelCount; ++i)
	{
		fRed = (float)rand() / RAND_MAX;
		fGreen = (float)rand() / RAND_MAX;
		fBlue = (float)rand() / RAND_MAX;

		m_pModelInfoList[i].d3dColor = D3DXVECTOR4(fRed, fGreen, fBlue, 1.0f);

		m_pModelInfoList[i].fXPos = (((float)rand()-(float)rand())/RAND_MAX) * 10.0f;
		m_pModelInfoList[i].fYPos = (((float)rand()-(float)rand())/RAND_MAX) * 10.0f;
		m_pModelInfoList[i].fZPos = ((((float)rand()-(float)rand())/RAND_MAX) * 10.0f) + 5.0f;
	}

	return true;
}

void CModelListClass::ShutDown()
{
	if(m_pModelInfoList)
	{
		delete [] m_pModelInfoList;
		m_pModelInfoList = nullptr;
	}

}

int CModelListClass::GetModelCount()
{
	return m_nModelCount;
}

void CModelListClass::GetData(int nIndex, float& fXPos, float& fYPos, float& fZPos, D3DXVECTOR4& d3dColor)
{
	fXPos = m_pModelInfoList[nIndex].fXPos;
	fYPos = m_pModelInfoList[nIndex].fYPos;
	fZPos = m_pModelInfoList[nIndex].fZPos;

	d3dColor = m_pModelInfoList[nIndex].d3dColor;
}